/**
 * Created with IntelliJ IDEA.
 * Description: 牛客网: FZ19 升序链表的删除
 * <a href="https://www.nowcoder.com/practice/22243a45ec9b425ea608d5fe3f6bb1f6?tpId=363&tqId=10618538&ru=/exam/company&qru=/ta/super-company23Year/question-ranking&sourceUrl=%2Fexam%2Fcompany">...</a>
 * User: DELL
 * Date: 2023-10-29
 * Time: 23:36
 */

class ListNode {
    int val;
    ListNode next = null;

    public ListNode(int val) {
        this.val = val;
    }
}


public class Solution {
    /**
     * 解题思路:
     * 本题较为简单,即分别定义两个节点标记为,然后依次往后遍历,
     * 若遇到相同的直接删除即可.
     *
     * @param head
     * @return
     */
    public ListNode deleteDuplicates(ListNode head) {
        ListNode cur = head;
        // 这里设定为 -101 是因为节点 val 的取值为 [-100,100]
        ListNode preCur = new ListNode(-101);
        preCur.next = cur;
        while (cur != null) {
            if (preCur.val == cur.val) {
                preCur.next = cur.next;
                cur = cur.next;
            } else {
                preCur = cur;
                cur = cur.next;
            }
        }
        return head;
    }
}